/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package action.comment;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.interceptor.ServletRequestAware;
import po.Activity;
import po.Comment;
import po.User;
import service.ActivityService;
import service.OrgService;
/**
 *
 * @author HX
 */

public class ViewCommentsAction extends ActionSupport implements ServletRequestAware
{
    private ActivityService activityService;
    private OrgService orgService;
    private HttpServletRequest request;
    private List<Comment> comments;
    private boolean isAdmin;
    private int activityId;
    private int orgId;

     @Override
    public String execute()
     {
         int userId;
         String msg;
         if (ActionContext.getContext().getSession().get("user") == null) {
            msg = "you should login first";
            request.setAttribute("msg", msg);
            return ERROR;
         }
         userId = ((User)ActionContext.getContext().getSession().get("user")).getId();
         if(request.getParameter("activityId")==null)
         {
             msg="no activity id!!!";
             request.setAttribute("msg", msg);
             return ERROR;
         }
         activityId = Integer.parseInt(request.getParameter("activityId"));
         orgId = Integer.parseInt(request.getParameter("orgId"));
         isAdmin = orgService.isLeader(userId, orgId);
         comments = activityService.getComments(activityId);

         return SUCCESS;
     }

    public void setActivityService(ActivityService activityService)
    {
        this.activityService=activityService;
    }

    public ActivityService getActivityService()
    {
        return this.activityService;
    }

    public List<Comment> getComments() {
        return comments;
    }

    public void setComments(List<Comment> comments) {
        this.comments = comments;
    }

    public void setServletRequest(HttpServletRequest request)
    {
        this.request=request;
    }

    public boolean isIsAdmin() {
        return isAdmin;
    }

    public void setIsAdmin(boolean isAdmin) {
        this.isAdmin = isAdmin;
    }

    public int getActivityId() {
        return activityId;
    }

    public void setActivityId(int activityId) {
        this.activityId = activityId;
    }

    public OrgService getOrgService() {
        return orgService;
    }

    public void setOrgService(OrgService orgService) {
        this.orgService = orgService;
    }

    public int getOrgId() {
        return orgId;
    }

    public void setOrgId(int orgId) {
        this.orgId = orgId;
    }

}

